{% extends "oa/base.html" %}
{% block title %} 部门费用统计 {% endblock %}
{% block content %}
    <section class="wrapper">
        <section class="panel">
            <div class="panel-heading">
                <h3>
                    部门费用统计
                </h3>
            </div>
            <div class="panel-body table-responsive">
                    <div class="col-lg-12">
                        <div class="panel">
                            <div class="panel-body">
                                <form class="form-inline" method="get" action="{{ request.path }}">
                                    <div class="form-group">
                                        <label for="date_start">开始日期：</label>
                                        <input type="date" class="form-control" id="date_start" name="date_start"
                                               value="{{ request.GET.date_start }}">
                                    </div>
                                    <div class="form-group">
                                        <label for="date_end">截止日期：</label>
                                        <input type="date" class="form-control" id="date_end" name="date_end"
                                               value="{{ request.GET.date_end }}">
                                    </div>
                                    <div class="form-group">
                                        <button type="submit" class="btn btn-info"><span>搜索</span></button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                <div class="col-lg-12">
                    <h3>汇总</h3>
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>月份</th>
                                <th class="text-right">销售额</th>
                                <th class="text-right">出厂成本</th>
                                <th class="text-right">毛利率%</th>
                                <th class="text-right">销售费用</th>
                                <th class="text-right">市场费用</th>
                                <th class="text-right">管理费用</th>
                                <th class="text-right">利润</th>
                                <th class="text-right">净利润%</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for m, d in summary.items %}
                            <tr>
                                <td>{{ m }}</td>
                                <td class="text-right">{{ d.total_income|floatformat:'2' }}</td>
                                <td class="text-right">{{ d.product_costs|floatformat:'2' }}</td>
                                <td class="text-right">{{ d.gross_profit_rate }}</td>
                                <td class="text-right">{{ d.sales_cost|floatformat:'2' }}</td>
                                <td class="text-right">{{ d.marketing_cost|floatformat:'2' }}</td>
                                <td class="text-right">{{ d.manage_cost|floatformat:'2' }}</td>
                                <td class="text-right">{{ d.total_profits|floatformat:'2' }}</td>
                                <td class="text-right">{{ d.net_profit_rate }}</td>
                            </tr>
                        {% endfor %}
                            <tr>
                                <td>合计</td>
                                <td class="text-right">{{ summary_sum.total_income|floatformat:'2' }}</td>
                                <td class="text-right">{{ summary_sum.product_costs|floatformat:'2' }}</td>
                                <td class="text-right">{{ summary_sum.gross_profit_rate }}</td>
                                <td class="text-right">{{ summary_sum.sales_cost|floatformat:'2' }}</td>
                                <td class="text-right">{{ summary_sum.marketing_cost|floatformat:'2' }}</td>
                                <td class="text-right">{{ summary_sum.manage_cost|floatformat:'2' }}</td>
                                <td class="text-right">{{ summary_sum.total_profits|floatformat:'2' }}</td>
                                <td class="text-right">{{ summary_sum.net_profit_rate }}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="col-lg-12">
                    <h3>明细</h3>
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>月份</th>
                            <th>部门</th>
                            <th class="text-right">销售额</th>
                            <th class="text-right">出厂成本</th>
                            <th class="text-right">销售费用</th>
                            <th class="text-right">市场费用</th>
                            <th class="text-right">管理费用</th>
                            <th class="text-right">利润</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for month, d in data.items %}
                            {% for department, r in d.items %}
                                <tr>
                                    <td>{{ month }}</td>
                                    <td>{{ department }}</td>
                                    <td class="text-right">{{ r.total_income|floatformat:'2' }}</td>
                                    <td class="text-right">{{ r.product_costs|floatformat:'2' }}</td>
                                    <td class="text-right">{{ r.sales_cost|floatformat:'2' }}</td>
                                    <td class="text-right">{{ r.marketing_cost|floatformat:'2' }}</td>
                                    <td class="text-right">{{ r.manage_cost|floatformat:'2' }}</td>
                                    <td class="text-right">{{ r.total_profits|floatformat:'2' }}</td>
                                </tr>
                            {% endfor %}
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </section>
    </section>
{% endblock %}